<template>
  <div class="container">loading</div>
</template>

<script>
import { mgop } from "@aligov/jssdk-mgop";
import getParam from '@/utils/parsingUrl'
import global from '@/global'

export default {
  data() {
    return {
      // result: '',
    };
  },
  created() {
    localStorage.removeItem("token");


    // console.log('getParam', this.$uitls)
    const isNewPlatform =
      window.location.href.indexOf("mapi.zjzwfw.gov.cn") > -1;

    // 政务中台环境
    if (isNewPlatform) {
      const ticket = getParam("ticket", window.location.href);
      const sessionTicket = sessionStorage.getItem("ticket");
      let reTicket = ticket;

      if (ticket?.indexOf("#/") > 0) {
        reTicket = ticket.replace("#/", "");
      }

      // console.log('location.url:', reTicket)
      // console.log('sessionTicket:', sessionTicket)

      if (reTicket || sessionTicket) {
        mgop({
          api: "mgop.zdwx.tsbft.doLogin", // 必须
          host: "https://mapi.zjzwfw.gov.cn/", // 'https://mapi.zjzwfw.gov.cn/'
          dataType: "JSON",
          type: "GET",
          header: { ticket: ticket || sessionTicket },
          data: { ticket: reTicket || sessionTicket },
          appKey: global.appKey, // 必须
          onSuccess: (response) => {
            const resData = response.data.result || {};
            localStorage.setItem("token", resData.token);

            // 浙政钉埋点 ⬇
            // 设置会员昵称
            // eslint-disable-next-line no-undef
            // if (resData.userName){
            //   aplus_queue.push({
            //     action: "aplus.setMetaInfo",
            //     arguments: ["_user_nick", resData.userName]
            //   })
            // }
            // 设置会员 ID
            // eslint-disable-next-line no-undef
            // if (resData.userId){
            //   aplus_queue.push({
            //     action: "aplus.setMetaInfo",
            //     arguments: ["_user_id", resData.userId]
            //   })
            // }
            // 浙政钉埋点 ⬆

            this.$router.push("/home");
          },
          onFail: (err) => {
            console.log(err, "err");
          },
        });
      } else {
        setTimeout(() => {
          window.location.href = encodeURI(
            `https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=${global.serviceCode}&goto=https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2001987644/lastTest/index.html?debug=true`
          );
          // 'https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=BCDSGA_f71b780e27d155580f282401b3a255e1&goto&goto=https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2002282000/lastTest/index.html?debug=true'
        }, 20);
      }
    }
  },
};
</script>

<style lang="less" scoped>
.container {
  padding-top: 10px;
  text-align: center;
  color: #333;
}
</style>
